# app.py
import mimetypes
from datetime import datetime

import click
from flask import Flask

from admin import register_bp_admin
from api import register_api_bp
from extensions import register_extensions, db
from frontend import register_bp_frontend
from models import User, Category, Website


def create_app():
    mimetypes.add_type('image/svg+xml', '.svg')
    app = Flask(__name__)
    app.config.from_object('config.Config')

    @app.context_processor
    def inject_current_year():
        beian = '闽ICP备2024080265号-1'
        return {'current_year': datetime.now().year, 'beian': beian}


    # 初始化扩展
    register_extensions(app)
    # 注册蓝图admin
    register_bp_admin(app)
    register_bp_frontend(app)
    #  api注册蓝图
    register_api_bp(app)

    return app

if __name__ == '__main__':
    app = create_app()
    app.run(debug=True, host='0.0.0.0', port=5050)
